package cn.itcast.health.quartz;

import cn.itcast.health.commons.resources.RedisConstant;
import cn.itcast.health.commons.utils.QiniuUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

import java.util.Set;

@Component("qiniuyunCleanImageObject")
public class QiniuyunCleanImageObject {
    @Autowired
    private JedisPool jedisPool;
    public   void  run(){
           System.out.println("-----quartz  is  running ----");
           //获取redis  存储的两个集合   比对 差异  七牛云 删除
           Jedis jedis = jedisPool.getResource();
           Set<String> sdiff = jedis.sdiff(RedisConstant.SETMEAL_PIC_RESOURCES, RedisConstant.SETMEAL_PIC_DB_RESOURCES);
               if(sdiff.size()>0){
                   System.out.println("-----clean img  is  running ----");
                   for (String s : sdiff) {
                       QiniuUtils.deleteFileFromQiniu(s);//  七牛云 多余垃圾图片 已经被清除
                   }
                   //  redis  保存 图片清理
                   jedis.del(RedisConstant.SETMEAL_PIC_RESOURCES,RedisConstant.SETMEAL_PIC_DB_RESOURCES);
               }
                jedis.close();

       }
}
